<%@ page language="java"  pageEncoding="UTF-8" %>
<%@ page import="com.shopping.modean.*" %>
<%@ page import="com.shopping.service.*" %>
<%@ page import="java.util.*" %>
<%@  include file="_session_check.jsp" %>

<%
  request.setCharacterEncoding("UTF-8");
  String pidStr = request.getParameter("pid");  
  int pid = pidStr == null ? 0 : Integer.parseInt(pidStr);  
  String action = request.getParameter("action");
  if(action != null && action.trim().equals("categoryAdd")) {
	  String name = request.getParameter("name");
	  String descr = request.getParameter("descr");
	  
	  
	  CategoryService categoryService = new CategoryService();
	  if(pid == 0) {
     	  categoryService.addRootCategory(name, descr);
	  } else {
		  categoryService.addChildCategory(pid,name, descr);
	  }
	  response.sendRedirect("category_list.jsp");
	  return;
  }

%>

<!DOCTYPE html>
<html>
<head>
  <title>添加分类</title>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  
  <script type="text/javascript">
  	function toListCategory() {
  		var form = document.getElementById("category_add");
  		form.setAttribute("action","category_list.jsp");
  		form.submit();
  	}
  
  </script>	
  	  
</head>

<body>

  <form method="post" id="category_add" name="category_add" action="category_add.jsp">
    <input type="hidden" name="action" value="categoryAdd" />
    <input type="hidden" name="pid" value="<%=pid %>" />
	<table class="tableborder" align="center" cellpadding="4" cellspacing="1" width="97%">
        <tr>
           <td>&nbsp;</td>
        </tr>
        <tr>
           <td>&nbsp;</td>
        </tr>
        <tr>
          <td class="altbg1" width="21%"><span style="color:red">*</span>分类名称:</td>
          <td class="altbg2">
            <input id="name" name="name" size="25" maxlength="25" type="text"> 
            <span id="usermsg"></span>
          </td>
        </tr>
		
        <tr>
          <td class="altbg1" valign="top">分类描述:</td>
          <td class="altbg2"><textarea name="descr" cols="60" rows="5" id="descr"></textarea></td>
        </tr>
        <tr>
          <td class="altbg1"></td>
          <td class="altbg2">
          	<input name="regsubmit" value="提 &nbsp; 交" type="submit">
          	<input name="listCategory" value="查看分类列表" type="button" onClick="toListCategory()">
          </td>
        </tr>
      </tbody>
    </table>
    
  </form>
  
</body>
</html>